package org.jsrml.core.base.service;

import org.hibernate.Criteria;
import org.jsrml.common.persistence.BaseDao;
import org.jsrml.core.base.command.DeleteResourceCo;
import org.jsrml.core.base.command.SaveResourceCo;
import org.jsrml.core.base.entity.Resource;
import org.jsrml.core.base.qo.ResourceQO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ResourceService extends BaseDao<Resource, ResourceQO>{

	public Resource createResource(SaveResourceCo command) {
		Resource resource = new Resource();
		resource.create(command);
		save(resource);
		return resource;
	}

	public Resource modifyResource(SaveResourceCo command) {
		Resource resource = get(command.getResourceId());
		resource.modify(command);
		save(resource);
		return resource;
	}

	public void deleteResource(DeleteResourceCo command) {
		delete(command.getResourceId());
	}

	@Override
	protected Criteria buildCriteria(Criteria criteria, ResourceQO qo) {
		return criteria;
	}

	@Override
	protected Class<Resource> getEntityClass() {
		return Resource.class;
	}
}
